package com.yfp.system.service.impl;

import com.yfp.system.api.domain.SysRole;
import com.yfp.system.domain.SysUserCompany;
import com.yfp.system.domain.SysUserCompanyDTO;
import com.yfp.system.mapper.SysRoleMapper;
import com.yfp.system.mapper.SysUserCompanyMapper;
import com.yfp.system.service.SysUserCompanyService;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import java.util.List;
/**
 * (SysUserCompany)表服务实现类
 *
 *
 * @since 2024-01-15 17:52:31
 */
@Service("sysUserCompanyService")
public class SysUserCompanyServiceImpl implements SysUserCompanyService {
    @Resource
    private SysUserCompanyMapper sysUserCompanyMapper;
    @Resource
    private SysRoleMapper sysRoleMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param  主键
     * @return 实例对象
     */
    @Override
    public SysUserCompany queryById( String id) {
        return this.sysUserCompanyMapper.queryById();
    }

    /**
     * 分页查询
     *
     * @param sysUserCompany 筛选条件
     * @return 查询结果
     */
    @Override
    public List<SysUserCompany> queryByPage(SysUserCompany sysUserCompany) {
        return this.sysUserCompanyMapper.queryAllByLimit(sysUserCompany);
    }

    /**
     * 新增数据
     *
     * @param sysUserCompany 实例对象
     * @return 实例对象
     */
    @Override
    public SysUserCompany insert(SysUserCompanyDTO sysUserCompany) {
        sysUserCompanyMapper.deleteById(Long.parseLong(sysUserCompany.getRoleId()));
        if (!sysUserCompany.getSysUserCompanies().isEmpty()){
            this.sysUserCompanyMapper.insert(Long.parseLong(sysUserCompany.getRoleId()),sysUserCompany.getSysUserCompanies());
        }
        SysRole sysRole = new SysRole();
        sysRole.setRoleId(Long.valueOf(sysUserCompany.getRoleId()));
        sysRole.setDataScope(sysUserCompany.getDataScope());
        sysRole.setMenuCheckStrictly(sysUserCompany.isMenuCheckStrictly());
        sysRole.setDeptCheckStrictly(sysUserCompany.isDeptCheckStrictly());
        sysRoleMapper.updateRole(sysRole);
        return null;
    }

    /**
     * 修改数据
     *
     * @param sysUserCompany 实例对象
     * @return 实例对象
     */
    @Override
    public SysUserCompany update(SysUserCompanyDTO sysUserCompany) {
        sysUserCompanyMapper.deleteById(Long.parseLong(sysUserCompany.getRoleId()));
        if (!sysUserCompany.getSysUserCompanies().isEmpty()){
            this.sysUserCompanyMapper.insert(Long.parseLong(sysUserCompany.getRoleId()),sysUserCompany.getSysUserCompanies());
        }
        SysRole sysRole = new SysRole();
        sysRole.setRoleId(Long.valueOf(sysUserCompany.getRoleId()));
        sysRole.setDataScope(sysUserCompany.getDataScope());
        sysRole.setMenuCheckStrictly(sysUserCompany.isMenuCheckStrictly());
        sysRole.setDeptCheckStrictly(sysUserCompany.isDeptCheckStrictly());
        sysRoleMapper.updateRole(sysRole);
        return null;
    }
}
